package com.zyy.seckill.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;



/**   消息队列实现消息分发 （topic）
 * @Author: zyy
 * @DateTime: 2021/10/5 18:12
 */

@Configuration
public class RabbitmqConfig {
    public static final String QUEUE_NAME ="seckillQueue";
    public static final String EXCHANGE_NAME ="seckillExchange";

    @Bean
    public Queue queue(){
        return new Queue(QUEUE_NAME);
    }
    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange(EXCHANGE_NAME);
    }

    @Bean
    public Binding binding(@Qualifier("queue")Queue queue,
                           @Qualifier("topicExchange") TopicExchange topicExchange){
        return BindingBuilder.bind(queue).to(topicExchange).with("seckill.#");
    }

}
